import { cloneDeep } from "lodash"

// 筛选路由的方法 深拷贝
function filterRoutes(routes, target, result = []) {
  // if(target == undefined) return []
  routes = cloneDeep(routes)
  for (let i = 0; i < routes.length; i++) {
    if (routes[i].children && routes[i].children.length) {
      filterRoutes(routes[i].children, target)
    }
    // 没有
    if (!target.includes(routes[i].name)) {
      // 删除
      routes.splice(i, 1)
      i--;

    } else {
      // 存在就添加进去
      result.push(routes[i])
    }
  }

  return result
}
export default filterRoutes